// Import the needed java packages and classes
importPackage(java.util);
importClass(javax.swing.JOptionPane);

function bracetopen() {

    if(isSingleLineComment()) {
        TARGET.replaceSelection("{");
    } else if (isMultiLineComment()){
        var a = AU.getIndent(AU.getLineAt(TARGET, TARGET.getCaretPosition()));
        TARGET.replaceSelection("{\n"+a+"    \n"+a+"}#");
        TARGET.setCaretPosition(TARGET.getCaretPosition()-3-(a.length()));
    } else {
        var b = AU.getIndent(AU.getLineAt(TARGET, TARGET.getCaretPosition()));
        TARGET.replaceSelection("{\n"+b+"    \n"+b+"}");
        TARGET.setCaretPosition(TARGET.getCaretPosition()-2-(b.length()));
    }
}

function isSingleLineComment() {
    return AU.getTokenStringAt(SDOC,TARGET.getCaretPosition()-1).contains("##");
}

function isMultiLineComment() {
    return TARGET.getText(TARGET.getCaretPosition()-1, 1) == "#";
}